package com.neuedu.my12306.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.neuedu.my12306.service.IUserInfoService;
import com.neuedu.my12306.service.impl.IUserInfoServiceImpl;

/**
 * Servlet implementation class UserDeleteServlet
 */
@WebServlet("/UserDeleteServlet.do")
public class UserDeleteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private IUserInfoService userInfoService;
    public UserDeleteServlet() {
        super();
        userInfoService =new IUserInfoServiceImpl();
        

    }

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//1.在接收数据前进行编码转换(统一使用过滤器转换)
		//2.
		String[] userIds = request.getParameterValues("userName");
		//3.
		boolean ret = userInfoService.deleteByIds(userIds);
		
		if(ret) {
			//删除成功，刷新列表数据
			response.sendRedirect(request.getContextPath()+"/UserAdminServlet.do");
		}else {
			//删除失败，跳转到一个操作错误提示页
			//页面跳转使用重定向后，需要使用HttpSession传递数据
			request.getSession().setAttribute("MSG", "删除用户信息失败！");
			request.getSession().setAttribute("BACKURL", request.getContextPath()+"/UserAdminServlet.do");
			response.sendRedirect(request.getContextPath()+"/error.jsp");
		}
	}

}
